"""
Train our tf-idf weighted svm.

[TODO](zbw): complete idf computation. compute the weighted vector.
"""

import numpy as np
from model.kernel_svm import *
from gensim.models import KeyedVectors
from utils.doc_tool import *
from utils.error_analysis import *

# load in our data
w2v = KeyedVectors.load_word2vec_format('w2v/Lyric_ChineseEmbedding.txt',binary=False)

# load in our training data and val data
row_train = np.load('Dataset/data/train.npy')
row_val = np.load('Dataset/data/val.npy')
train_data = dataset2mat(row_train, w2v)
val_data = dataset2mat(row_val, w2v)

# compute idf
idf = dataset2idf(dataset, w2v.keys())

# compute the tf-idf weighted vector and trainsform it into numpy
train = []
train_label = []
val = []
val_label = []

for i in range(len(train_data)):
    avg_train.append() 
    train_label.append(int(train_data[i][1]))
for i in range(len(val_data)):
    avg_val.append()
    val_label.append(int(val_data[i][1]))
                           
model = SVC(kernel='rbf',decision_function_shape ='ovr',gamma=5.,C=1.0)
model.fit(train, train_label)
pred_y = model.predict(val)
pred_y = np.array(pred_y)
true_y = np.array(val_label)
error_analysis(pred_y, true_y)